package com.zdj.presentation.modules.user.views;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;

import com.zdj.presentation.R;
import com.zdj.presentation.base.BaseActivity;
import com.zdj.presentation.databinding.ActivityUserBinding;
import com.zdj.presentation.modules.user.vms.UserVm;

public class UserActivity extends BaseActivity<UserVm, ActivityUserBinding> implements SwipeRefreshLayout.OnRefreshListener{

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewModel.loadUsers();
    }

    @Override
    protected void initVms() {
        viewModel = new UserVm(this);
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_user;
    }

    @Override
    protected void setViewModel2Binding() {
        viewDatabinding.setUserVm(viewModel);
        viewDatabinding.content.setUserVm(viewModel);
    }

    @Override
    protected void initView() {

        viewDatabinding.content.recycleViewUser.setLayoutManager(new LinearLayoutManager(this));
        viewDatabinding.content.recycleViewUser.setItemAnimator(new DefaultItemAnimator());
        /**
         * 设置下拉刷新的progress颜色 <br/>
         * modify by dengjie at 2016/01/06 13:31
         */
        viewDatabinding.content.recycleViewUser.setRefreshingColorResources(R.color.colorPrimary,
                R.color.colorPrimaryDark, R.color.colorPrimaryLight,
                R.color.colorAccent);
        viewDatabinding.content.recycleViewUser.setRefreshListener(this);
    }

    @Override
    public void onRefresh() {
        viewModel.refreshUsers();
    }
}
